package cn.seocoo.platform.api.controller.common;

import cn.seocoo.platform.api.util.JSONResult;
import cn.seocoo.platform.base.dto.BaseCommonDto;
import cn.seocoo.platform.common.core.domain.AjaxResult;
import cn.seocoo.platform.common.utils.AmountUtils;
import cn.seocoo.platform.rule.domain.Rule;
import cn.seocoo.platform.rule.service.IRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: CommonRuleController
 * @description: 公共规则
 * @author: wujian
 * @Date: 2019-12-23 19:40
 **/
@Api(value = "登录模块", description = "登录模块")
@RestController
@RequestMapping("/api/common")
public class CommonRuleController {

    @Autowired
    private IRuleService iRuleService;

    /**
     * @return cn.seocoo.platform.common.core.domain.AjaxResult
     * @Author WuJian
     * @Description //获取用户协议
     * @Date 15:37 2019/12/23
     * @Param [loginName]
     **/
    @ApiOperation("获取用户协议")
    @GetMapping("/getUserRule")
    public JSONResult getUserRule(String type) {
        try {
            BaseCommonDto dto  = iRuleService.selectRuleByType(type);
            if(Rule.AMOUNT_RULE.equals(type)){
                String amount = AmountUtils.changeF2Y(dto.getText());
                dto.setText(amount);
            }
            return JSONResult.ok(dto);
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.errorMsg(JSONResult.ERROR_MSG);
        }
    }


}
